package it.patamau.persistence;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class JDBCMapping {

	private Connection connection;

	public static void main(String args[]) {
		String driver = "com.mysql.jdbc.Driver";
		String url = "jdbc:mysql://localhost:3306/test";
		String user = "root";
		String pass = "";
		JDBCMapping map = new JDBCMapping();
		if(map.connect(driver, url, user, pass)){
			System.out.println("connected");
		}else{
			System.out.println("not connected");
		}
	}

	public JDBCMapping(){
		//hi!
	}
	
	public boolean connect(String driver, String url, String user, String pass) {
		try {
			Class.forName(driver);
			connection = DriverManager.getConnection(url, user, pass);
			return true;
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return false;
	}
	
	public void close(){
		if(connection!=null){
			try {
				connection.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
}
